package practice.practice_0828;

import java.util.Random;
import java.util.Scanner;

public class RandomName {//随机点名器
    //存储全班同学姓名
    public static void storeName(String []student){
        for(int i=0;i<student.length;i++) {
            System.out.println("存储第" + (i+1 )+ "个姓名");
            Scanner sc=new Scanner(System.in);
            student[i]=sc.next();
        }

    }
    //总览全班同学姓名
    public static String [] printAll(String [] student){
        for (int i = 0; i < student.length; i++) {
            System.out.println("第"+i+"个学生是："+student[i]);
        }
        return student;
    }

    //随机点取其中一人姓名
    public static void randomName(String[]student){
        Random ra=new Random();
        int index=ra.nextInt(student.length);
        System.out.println("被点到名的同学是"+student[index]);
    }
    public static void main(String[] args) {
        String [] student=new String[3];
        System.out.println("-----------随机点名器-----------");
        storeName(student);
        printAll(student);
        randomName(student);
    }

}
